define(function (require, exports, module) {
    var angular = require('angular');
    require("pagination");
    require("angular-ui");
    var dialog = require("dialogplus");
    var util = require("util");
    var api_prefix = G_CONFIG["api_prefix"]; //api前缀
    var datepicker = require("datepicker");
    var fundCtrl = require('/public/js/myservice/contract/editinc/receivable-fund-ctrl');
    var invoiceCtrl = require('/public/js/myservice/contract/editinc/receivable-invoice-ctrl');
    var refundCtrl = require('/public/js/myservice/contract/editinc/receivable-refund-ctrl');
    require('/public/js/myservice/common/row-toolbar');
    require('/public/js/myservice/contract/contract-common');

    angular.module('ContractReceivable', ['ngUI', 'ContractReceivableFund', 'rowToolbar', 'ContractCommonService', 'ContractReceivableInvoice', 'ContractReceivableRefund'])

        .controller('contractReceivableCtrl', ['$scope', 'receivableFundService', 'contractCommonService', '$routeParams', 'receivableInvoiceService', 'receivableRefundService',
            function ($scope, receivableFundService, contractCommonService, $routeParams, receivableInvoiceService, receivableRefundService) {
                $scope.receivableFundService = receivableFundService;
                $scope.receivableInvoiceService = receivableInvoiceService;
                $scope.receivableRefundService = receivableRefundService;
                $scope.title = 'receivable edit';
                $scope.contractBaseInfo = {};

                var contractId = $routeParams.id;
                //获取合同信息
                contractCommonService.getContract(contractId, function (data) {
                    $scope.contractBaseInfo = data.contract;
                    $scope.$applyAsync();
                })

                //获取应收信息
                contractCommonService.getContractUnifiedInfo(contractId, function (data) {
                    $scope.receivableInfo = data;
                    $scope.$applyAsync();
                })

                //款项回写刷新
                $scope.reloadFunds = function () {
                    //获取应收信息
                    contractCommonService.getContractUnifiedInfo(contractId, function (data) {
                        $scope.receivableInfo.receivables = data.receivables;
                        $scope.$applyAsync();
                    });
                };

                //新增发票回写刷新
                $scope.reloadInvoices = function () {
                    //获取应收信息
                    contractCommonService.getContractUnifiedInfo(contractId, function (data) {
                        $scope.receivableInfo = data;
                        $scope.$applyAsync();
                    });
                };

                //新增回款回写刷新
                $scope.reloadRefund = function () {
                    //获取应收信息
                    contractCommonService.getContractUnifiedInfo(contractId, function (data) {
                        $scope.receivableInfo = data;
                        $scope.$applyAsync();
                    });
                };
            }]);
})
;